package com.ruoyi.web.controller.test;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.MessageUtils;
import org.hibernate.validator.constraints.Length;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Locale;

/**
 * 通用请求处理
 *
 * @author ruoyi
 */
@Validated
@RestController
@RequestMapping("/common")
public class I18TestController {
    private static final Logger log = LoggerFactory.getLogger(I18TestController.class);

    /**
     * 测试i18
     *
     * @apiNote 系统自动加载的国际化文件
     *
     */
    @Anonymous
    @GetMapping("/i18")
    public R i18Test_auto() {
        return R.ok(MessageUtils.message("demo.test.i18"));
    }



    /**
     * 测试i18
     *
     * @apiNote 系统自动加载的国际化文件
     *
     */
    @Anonymous
    @PostMapping("/i18")
    public R i18Test_auto_post() {
        return R.ok(MessageUtils.message("demo.test.i18"));
    }

    /**
     * 测试i18
     *
     * @apiNote 多个参数
     *
     */
    @Anonymous
    @GetMapping("/i18_multi_params")
    public R i18Test_multi_params() {
        return R.ok(MessageUtils.message("demo.test.i18_multi_params","123","456","789"));
    }

    /**
     * 测试i18
     *
     * @apiNote 指定国际化文件
     *
     */
    @Anonymous
    @GetMapping("/i18_appoint")
    public R i18Test_appoint() {
        return R.ok(MessageUtils.message("demo.test.i18",Locale.US));
    }


    /**
     * 测试i18
     *
     * @apiNote 指定国际化文件
     *
     */
    @Anonymous
    @GetMapping("/i18Test_validate1")
    public R i18Test_validate1(@Length(min = 10,message = "i18_demo.test.i18_validate_name_not_null")   String name) {
        System.out.println(name);
        return R.ok(MessageUtils.message("demo.test.i18"));
    }

    /**
     * 测试i18
     *
     * @apiNote 指定国际化文件
     *
     */
    @Anonymous
    @GetMapping("/i18Test_validate2")
    public R i18Test_validate2(@Valid I18Dto2 dto2) {
        System.out.println(dto2.getName());
        return R.ok(MessageUtils.message("demo.test.i18"));
    }
}
